﻿//-----------------------------------------------------------------------
// <copyright file="RuleDescriptorFactory.cs">
//     Copyright (c) Nicole Calinoiu. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

using Microsoft.FxCop.Sdk;
using Microsoft.VisualStudio.CodeAnalysis.Extensibility;

using Bordecal.FxCop.Sdk;

namespace Bordecal.FxCop.Rules
{
	[SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented",
			Justification = "False positive.")]
	internal static class RuleDescriptorFactory
	{
		private const string Email = "calinoiu@gmail.com";
		private const string Owner = "Nicole Calinoiu";

		internal static IRuleDescriptor CreateSingleResolutionDescriptor<TRule>(
				RuleCategory category,
				string name,
				string description,
				int certainty,
				FixCategories fixCategories,
				MessageLevel messageLevel,
				string resolution)
			where TRule : IRule
		{
			return new SingleResolutionRuleDescriptor(
				category.ToString(),
				name,
				description,
				RuleDescriptorFactory.GetRuleCheckId(typeof(TRule)),
				RuleDescriptorFactory.Owner,
				RuleDescriptorFactory.Email,
				RuleDescriptorFactory.GetRuleUrl(typeof(TRule)),
				certainty,
				fixCategories,
				messageLevel,
				resolution);
		}

		private static string GetRuleCheckId(Type type)
		{
			return "BC" + (int)Enum.Parse(typeof(CheckId), type.Name);
		}

		private static Uri GetRuleUrl(Type type)
		{
			return new Uri(string.Format(
				CultureInfo.InvariantCulture,
				@"http://bordecalfxcop.codeplex.com/wikipage?title={0}",
				type.Name));
		}
	}
}